Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@npmcli/arborist

Package Overview
Dependencies
Maintainers
5
Versions
193
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@npmcli/arborist

Manage node_modules trees

  • 6.5.1
  • backport
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9M
decreased by-25.58%
Maintainers
5
Weekly downloads
 
Created

What is @npmcli/arborist?

@npmcli/arborist is a library for managing and manipulating the node_modules tree in a Node.js project. It provides a programmatic interface to interact with the dependency tree, allowing you to perform tasks such as installing, updating, and removing packages, as well as analyzing the dependency graph.

What are @npmcli/arborist's main functionalities?

Load the dependency tree

This feature allows you to load the current state of the node_modules tree. The `loadActual` method reads the actual state of the installed packages.

const Arborist = require('@npmcli/arborist');
const arborist = new Arborist();

async function loadTree() {
  const tree = await arborist.loadActual();
  console.log(tree);
}

loadTree();

Install a package

This feature allows you to install a new package into your project. The `reify` method is used to apply changes to the node_modules tree, and the `add` option specifies the package to install.

const Arborist = require('@npmcli/arborist');
const arborist = new Arborist({ path: '.' });

async function installPackage() {
  await arborist.reify({ add: ['lodash'] });
  console.log('Package installed');
}

installPackage();

Remove a package

This feature allows you to remove a package from your project. The `reify` method is used to apply changes to the node_modules tree, and the `rm` option specifies the package to remove.

const Arborist = require('@npmcli/arborist');
const arborist = new Arborist({ path: '.' });

async function removePackage() {
  await arborist.reify({ rm: ['lodash'] });
  console.log('Package removed');
}

removePackage();

Analyze the dependency graph

This feature allows you to analyze the dependency graph of your project. By loading the actual state of the node_modules tree, you can iterate over the dependencies and inspect their details.

const Arborist = require('@npmcli/arborist');
const arborist = new Arborist();

async function analyzeGraph() {
  const tree = await arborist.loadActual();
  const dependencies = tree.children;
  dependencies.forEach(dep => {
    console.log(dep.name, dep.version);
  });
}

analyzeGraph();

Other packages similar to @npmcli/arborist

FAQs

Package last updated on 28 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc